
import Taro, { Component } from '@tarojs/taro'
import { AtList, AtListItem, AtButton } from 'taro-ui'
import { View } from '@tarojs/components'
import { DNavBar, Ddialog, DModal } from '@/components'
import sdk from '@/common/sdk'
import './setup.scss'
import http from '@/api'
export default class setup extends Component {
  constructor(props) {
    super(props),
      this.state = {
        isShow: false,
        title: "设置",
        isformatShow:false
      }
  }

  componentDidShow() {
    sdk.setTitleInfo(this.state.title)
  }

  onUseAgreement() {
    Taro.navigateTo({
      url: `/pages/useagreement/useagreement`
    })
  }
  onShareQR() {
    Taro.navigateTo({
      url: `/pages/shareqrcode/shareqrcode`
    })
  }
  onAboutChezhu() {
    Taro.navigateTo({
      url: `/pages/aboutchezhu/aboutchezhu`
    })
  }
  onPrivacy() {
    Taro.navigateTo({
      url: '/pages/privacy'
    })
  }
  isCall() {
    // let { isShow } = this.state
    // isShow = !isShow
    // this.setState({
    //   isShow
    // })
    Taro.setClipboardData({
      data: '4009991024',
      success: () => {
        Taro.showToast({
          title: '复制成功',
          icon: 'success'
        })
      }
    })
  }
  onCancelModal() {
    this.setState({
      isShow: false
    })
  }
  // 拨打电话
  handleSure() {
    this.setState({
      isShow: false
    }, () => {
      if (window.bridge) {
        window.bridge.callHandler('call', { 'tephone': 4009991024 }, function responseCallback(res) { })
      }
    })
  }

  onCloseHandle() {
    this.state.isShow = false
  }
  // 退出登录
  onOutLogin() {
	  http.logout().then(res=>{
		    Taro.showToast({
		      title: '退出登录',
		      duration: 800
		    }).then(() => {
		      localStorage.removeItem("X-Auth0-Token")

		      setTimeout(() => {
				  if (window.bridge) {
		        window.bridge.callHandler('logout', {}, function responseCallback(res) { })
				}
		      }, 1000)
		    })

	  })

  }
  // 注销账号
  onCancelAccount() {
	  http.onLogoutB().then(res=>{
		    Taro.showToast({
		      title: '注销账号',
		      duration: 800
		    }).then(() => {
          this.setState({
            isformatShow: false
          })
		      localStorage.removeItem("X-Auth0-Token")
		      setTimeout(() => {
				  if (window.bridge) {
		        window.bridge.callHandler('logout', {}, function responseCallback(res) { })
				}
		      }, 1000)
		    })

	  })
  }
  // 点击注销账号注销账号
  onLastHandle(){
    this.setState({
      isformatShow: true
    })
  }
  // 取消注销账号
  onFirstHandle(){
    this.setState({
      isformatShow: false
    })
  }
  //关闭弹出框
  handleCancel() {
    this.setState({
      isShow: false
    })
  }
  //确定拨打电话


  render() {
    const {
      isShow,
      title,
      isformatShow
    } = this.state
    const btnMarTop = {
      margin: '-20px 0 0 0'
    }
    return (
      <View className='b_setup'>
        <DNavBar title={title} className='b_setup_nav'></DNavBar>
        <View className='b_setup__box'>
          <AtList className='b_setup__list'>
            <AtListItem
              onClick={this.onUseAgreement.bind(this)}
              arrow='right'
              title='车煮用户协议'
            />
            <AtListItem
              onClick={this.onPrivacy.bind(this)}
              arrow='right'
              title='车煮隐私政策'
            />
            {/* <AtListItem
              onClick={this.onShareQR.bind(this)}
              arrow='right'
              title='分享二维码'
            /> */}
            <AtListItem
              onClick={this.onAboutChezhu.bind(this)}
              arrow='right'
              title='关于车煮平台'
            />
            <AtListItem
              onClick={this.isCall.bind(this)}
              arrow='right'
              title='客服热线4009991024'
            ></AtListItem>
          </AtList>
        </View>
        <View className='b_setup__footer'>
          <AtButton className='item_btn' onClick={this.onOutLogin.bind(this)}>退出登录</AtButton>
        </View>
         <View className='b_setup__footer' style={btnMarTop}>
          <AtButton className='item_btn' onClick={this.onLastHandle.bind(this)}>注销账号</AtButton>
        </View>
				<DModal isShow={isformatShow} title="提示" text="确认后会删除个人信息，请谨慎操作" firstbtn="取消" lastbtn="确定" onFirst={this.onFirstHandle.bind(this)}  onLast={this.onCancelAccount.bind(this)}></DModal>

        {
          isShow && <Ddialog isShow={isShow}
            content='确认拨打4009991024吗'
            btnText='确认'
            title='提示'
            onCancel={this.handleCancel.bind(this)}
            onSure={this.handleSure.bind(this)}
          ></Ddialog>
        }
        {
          // isShow && <a href={'tel:' + 4009991024}>111</a>
        }
        {/* <AtModal isOpened={isCall} className='b_setup__modal' onClose={this.onCloseHandle.bind(this)}>
          <AtModalContent>
            <Text className='b_setup__modal_title'>提示</Text>
            确认拨打 136-0005-3041 吗？
          </AtModalContent>
          <AtModalAction>
            <Button onClick={this.onCancelModal.bind(this)}>取消</Button>
            <Button className='b_setup__modal_confirm' onClick={this.onConfirmCall.bind(this)}>确认</Button>
          </AtModalAction>
        </AtModal> */}

      </View>

    )
  }

}
